-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
s3-sqs input: log a lambda event summary in case of errors #860
Conversation
Minimum allowed coverage is Generated by 🐒 cobertura-action against 99c147c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Maurizio, looks good!
handlers/aws/utils.py
Outdated
|
||
# We stop adding records to the summary once we reach | ||
# the `max_records` limit. | ||
if len(aws_sqs_summary[first_records_key]) < max_records: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you also break the loop when reaching that? If so you can reverse the check and add a break to avoid looping for nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was continuing the loop to get the total number of records.
Here's the lambda event structure (with minor changes for readability):
{
"Records": [
{
"messageId": "059f36b4-87a3-44ab-83d2-661975830a7d",
"receiptHandle": "AQEBwJnKyrHigUMZj6rYigCgxlaS3SLy0a...",
"body": "{\"Records\":[{\"awsRegion\":\"eu-west-1\",\"eventTime\":\"2024-01-31T19:06:30.680Z\",\"eventName\":\"ObjectCreated:Put\",\"eventSource\":\"aws:s3\",\"eventVersion\":\"2.1\",\"s3\":{\"bucket\":{\"arn\":\"arn:aws:s3:::mbranca-esf-data\",\"name\":\"mbranca-esf-data\"},\"object\":{\"key\":\"AWSLogs/123456/I-do-not-exist\"}}}]}",
"attributes": {
"ApproximateReceiveCount": "1",
"SentTimestamp": "1545082649183",
"SenderId": "AIDAIENQZJOLO23YVJ4VO",
"ApproximateFirstReceiveTimestamp": "1545082649185"
},
"messageAttributes": {
"myAttribute": {
"stringValue": "myValue",
"stringListValues": [],
"binaryListValues": []
}
},
"md5OfBody": "e4e68fb7bd0e697a0ae8f1bb342846b3",
"eventSource": "aws:sqs",
"eventSourceARN": "arn:aws:sqs:us-east-2:123456789012:my-queue",
"awsRegion": "us-east-2"
}
]
}
So my goal is to provide the total number of the following elements (hoppa jq
style):
.Records[].body.Records
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I see you point now, we can skip the inner loop 🤦
What does this PR do?
If there is an exception when processing a lambda event from the
s3-sqs
input, ESF summarizes the lambda event and adds the summary as extra information to the exception log message.The summary contains the essential elements for the lambda event. For the
s3-sqs
input, it includes the bucket ARN and the object key. The summary limits the number of records tomax_records
.ESF currently supports lambda event summary for
s3-sqs
only. We want to hear users' feedback before making additional changes or extending the summary to other input types.Why is it important?
For some error classes (e.g., encoding errors), knowing the S3 objects in flight in the lambda event helps speed up investigation and troubleshooting.
Users can achieve the same goal by enabling APM, but this extra log helps those users who do not or won't use APM for any reason.
Checklist
I have made corresponding changes to the documentationI have made corresponding change to the default configuration filesCHANGELOG.md
and updatedshare/version.py
, if my change requires a new release.How to test this PR locally
Deploy ESF and send an SQS message with a S3 that points to a non-existent S3 object:
aws sqs send-message \ --queue-url https://sqs.eu-west-1.amazonaws.com/627286350134/mbranca-esf-notifications \ --message-body '{"Records":[{"awsRegion":"eu-west-1","eventTime": "2024-01-31T19:06:30.680Z","eventName":"ObjectCreated:Put","eventSource":"aws:s3","eventVersion":"2.1","s3":{"bucket":{"arn":"arn:aws:s3:::mbranca-esf-data","name":"mbranca-esf-data"},"object":{"key":"AWSLogs/123456/I-do-not-exist"}}}]}'
Logs
Here is a sample log with the lambda event summary: